<?php
require_once('../includes/SmartyManager.class.php');
require_once('../includes/DB.class.php');
require_once('../includes/Verifier.class.php');
require_once('../includes/Filter.class.php');
require_once('../includes/MonitorFileAccountant.class.php');
require_once('../includes/SimpleTableExporter.class.php');

try{
$smarty = SmartyManager::getSmarty();
$monitor = new MonitorFileAccountant($_GET['id']);
$monitor->execute();

$query = 'select filename from little_monitor_file where id = '.$_GET['id'];
DB::query($query);
$row = DB::getResult()->fetch_assoc();
$monitorFilename = $row['filename'];

//echo $monitorFilename.'<br />';
$filename = iconv('utf-8', 'gbk', '监控'.'_('.pathinfo($monitorFilename, PATHINFO_FILENAME).')_'.date('YmdHis').'.xls');
//echo iconv('utf-8', 'gbk', $filename)."<br />";

//die();
$exp = new SimpleTableExporter($filename);
$exp->insertCustomData(array(
					$monitor->getCertificationNumber(),
					$monitor->getFacheNumber(),
				 	$monitor->getCertificationCodification(),
				 	$monitor->getSequenceNumber(),
				 	$monitor->getManufactory(),
				 	$monitor->getAuthenticationMark(),
				 	$monitor->getSteelNumber(),
				 	$monitor->getSize1(),
				 	$monitor->getSize2(),
				 	$monitor->getSize3(),
					$monitor->getCount(),
					$monitor->getUnitWeight(),
					$monitor->getOrderNumber(),
					$monitor->getOrderSubitemNumber(),
					$monitor->getUnitPrice(),
					$monitor->getMaterialNumber(),
					$monitor->getConsignmentBatch(),
					$monitor->getSampleBatch(),
					$monitor->getPurchaseNumber(),
					$monitor->getShipmentDate(),
					$monitor->getMonth(),
					$monitor->getVehicleNumber(),
					$monitor->getConsignee(),
					$monitor->getRemark(),
					$monitor->getStat()), 
	array('产品质量证明书号','发车证书号','产品质量证明书编号','批次','生产厂家','船级','材质','厚','宽','长','数量','单重',
				'订单号','订单子项号','受订单价','物料号','发货批次','批号','购单号','发货时间','合同月份','车号',
				'销售产家','备注','状态'), 
		'sheet1');
$exp->insertCustomData(array(
					$monitor->getNotInMainCertificationNumber(),
					$monitor->getNotInMainFacheNumber(),
				 	$monitor->getNotInMainCertificationCodification(),
				 	$monitor->getNotInMainSequenceNumber(),
				 	$monitor->getNotInMainManufactory(),
				 	$monitor->getNotInMainAuthenticationMark(),
				 	$monitor->getNotInMainSteelNumber(),
				 	$monitor->getNotInMainSize1(),
				 	$monitor->getNotInMainSize2(),
				 	$monitor->getNotInMainSize3(),
					$monitor->getNotInMainCount(),
					$monitor->getNotInMainUnitWeight(),
					$monitor->getNotInMainOrderNumber(),
					$monitor->getNotInMainOrderSubitemNumber(),
					$monitor->getNotInMainUnitPrice(),
					$monitor->getNotInMainMaterialNumber(),
					$monitor->getNotInMainSampleBatch(),
					$monitor->getNotInMainPurchaseNumber(),
					$monitor->getNotInMainShipmentDate(),
					$monitor->getNotInMainMonth(),
					$monitor->getNotInMainVehicleNumber(),
					$monitor->getNotInMainConsignee()),
	array('产品质量证明书号','发车证书号','产品质量证明书编号','批次','生产厂家','船级','材质','厚','宽','长','数量','单重',
				'订单号','订单子项号','受订单价','物料号','批号','购单号','发货时间','合同月份','车号',
				'销售产家'), 
		'sheet2');
$exp->export();
}catch(Exception $e){
	$smarty = SmartyManager::getSmarty();
	$smarty->assign('errMsg', $e);
	$smarty->assign('errTitle', '查询数据库时出现错误');
	$smarty->display('error.html');
	die();
}

?>